import Connector.ConnectorUtils;
import Connector.HttpStatus;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeServlet implements Servlet {

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    // Servlet提供的服务
    // 它的参数是ServletRequest ServletResponse，所以要改造Request Response
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {

        System.out.println("Servlet is at service.");

        // 得到response的PrintWriter
        PrintWriter out = servletResponse.getWriter();

        out.println("The current time is:");
        out.println(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()));
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
